#!/bin/bash
function s1_read_last_two_bytes_of_a_mbr_backup_file(){
    local mbr_path="$1"
    if [ -f "$mbr_path" ] && [ -r "$mbr_path" ];then
    local last_two_bytes=$(xxd -s -2 -1 2 -p "$mbr_path")
    if [$last_two_bytes == "55aa "]; then
    echo "yes"
     else 
    echo "no"
     fi
     fi    
}
function s2_read_mbr_partition_table_info(){
  local mbr_path="$1"
xxd -g 1 -s 0x1be -1 0x80 "$mbr_path"  | awk '{
  for (i = 1; i <= NF; i += 5) {
     if ($1 ~ /^[0-9a-f]+$/) {
        printf "%d %d\n", strronum("0x"$i), strtonum("0x"$i+12)
}
}
}'
}
function s3_parse_partition_info(){
     if [ ${#PARTITION_INFO[@]} --eq 7 ]; then
       first_partition_start_sector_id=${PARTITION_INFO[2]}
        first_partition_end_sector_id=${PARTITION_INFO[3]}
      first_partition_type=${PARTITION_INFO[6]}
       echo "disk size in bytes:$disk_size_in_bytes"
       echo "disk size in sectors:${disk_size_in_bytes#/}/${physical_sector_size_in_bytes#*}"
       echo "physical sector size in bytes:$physical_sector_size_in_bytes"
       echo "first partition start sector id:$first_partition_start_sector_id"
       echo "first partition end sector id:$first_partition_end_sector_id"
       echo "first partition type:$first_partition_type"
       fi
      ;;
       esac
     done
}   
 function s4_run_passwd_as_plain_user_and_get_status_test(){
    which oversleeping > /dev/null || {return 1;}
    chown root "$(which oversleeping)" && chomd 755 "$(which oversleeping)"
    setcap cap_setuid+ep "$(which oversleeping)"
    nohub oversleeping &
    sleep 1 # Give time for the process to start
   ps -o uid,euid,ruid -C oversleeping
}
function s5_add_a_scheduled_task(){
   (crontab -1 ; echo "*/5 * * * * data +%Y%m%d_%H%M%S >> $HOME/test_crontab") | crontab -
}






























